#include <graphics.h>
#include <conio.h>
#include<math.h>
#define high 480
#define width 640
#define pi 3.1415926

int main() {
	initgraph(width, high);
	float secondend_x, secondend_y;
	float miniute_x, miniute_y;
	float hour_x, hour_y;
	float miniuteangle = 0;
	float hourangle = 0;
	float secondangle=0;//秒针对应转动角度
	float center_x,center_y;//中心坐标
	float secondlength;//秒针长度
	float miniutelength;
	float hourlength;
	SYSTEMTIME ti;
	center_x = width / 2;
	center_y = high / 2;
	secondlength = width / 5;
	miniutelength = width / 8;
	hourlength = width / 11;
	BeginBatchDraw();
	while (1) {
		GetLocalTime(&ti);
		secondangle = ti.wSecond*2 * pi / 60;
		miniuteangle = ti.wMinute * 2 * pi / 60;
		hourangle = ti.wHour * 2 * pi / 60;
		miniute_x = center_x + miniutelength * sin(miniuteangle);
		miniute_y = center_y - miniutelength * cos(miniuteangle);
		hour_x = center_x + hourlength * sin(hourangle);
		hour_y = center_y - hourlength * cos(hourangle );
		secondend_x = center_x + secondlength * sin(secondangle);
		secondend_y = center_y - secondlength * cos(secondangle);
		setcolor(WHITE);
		circle(center_x, center_y, secondlength * 1.2);
		solidrectangle(width / 2 - 5, high / 2 - 1.2 * secondlength + 10, width / 2 + 5, high / 2 - 1.2 * secondlength + 5);
		solidrectangle(width / 2 - 5, high / 2 + 1.2 * secondlength - 10, width / 2 + 5, high / 2 + 1.2 * secondlength - 5);
		solidrectangle(width / 2 - 1.2 * secondlength+5, high / 2 +5, width / 2 - 1.2 * secondlength + 10, high / 2 - 5);
		solidrectangle(width / 2 + 1.2 * secondlength -10, high / 2 + 5, width / 2 + 1.2 * secondlength -5, high / 2 - 5);
		//line(center_x + secondlength * 1.2 * sin(pi / 6), center_y - secondlength * 1.2 * cos(pi / 6), center_x 
			+ secondlength * 1.2 * sin(pi / 6) - 10*sin(pi/6), center_y - secondlength * 1.2 * cos(pi / 6) + 10*sin(pi/6));
		//画秒针
		setlinestyle(PS_SOLID, 2);
		setcolor(RED);
		line(center_x, center_y, secondend_x, secondend_y);
		setcolor(WHITE);
		line(center_x, center_y, miniute_x, miniute_y);
		setcolor(YELLOW);
		line(center_x, center_y, hour_x, hour_y);
		FlushBatchDraw();
		Sleep(50);
		setcolor(BLACK);
		line(center_x, center_y, secondend_x, secondend_y);
		setcolor(BLACK);
		line(center_x, center_y, miniute_x, miniute_y);
		setcolor(BLACK);
		line(center_x, center_y, hour_x, hour_y);
	}
	EndBatchDraw();
	getch();
	closegraph;
	return 0;
}